<template>
  <div id='order'>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input v-model="queryInfo.query" placeholder="请输入搜索内容" clearable @clear="getOrderList">
            <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="orderList" border stripe>
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price" width="100px"></el-table-column>
        <el-table-column label="是否付款" prop="pay_status" width="100px">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status==='1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send" width="100px"></el-table-column>
        <el-table-column label="下单时间" prop="create_time | dateFormat">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150px">
          <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="showEditDialog"></el-button>
            <el-button type="success" icon="el-icon-location" size="mini" @click="showProgressDialog"></el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination :total="total" :current-page="queryInfo.pagenum" :page-size="queryInfo.pagesize"
        @size-change="handleSizeChange" @current-change="handlePagechange" layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[5,10,29,30]"></el-pagination>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog title="修改地址" :visible="editAddressDialogVisible" @close="editAddressDialogClosed" width="50%">
      <el-form v-model="editAddressForm" :rules="editAddressFormRules" ref="editAddressFormRef" label-width="90px">
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader expand-trigger="hover" :options="cityData" v-model="editAddressForm.address1"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="editAddressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="">确 定</el-button>
        <el-button @click="editAddressDialogClosed">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 显示物流信息 -->
    <el-dialog title="物流信息" :visible="progerssDialogVisible" @close="progerssDialogClosed" width="50%">
        <!-- timeline时间线 -->
        <el-timeline>
            <el-timeline-item v-for="(activity,index) in progressInfo" :key="index" :timestamp="activity.time">{{ activity.context }}</el-timeline-item>
        </el-timeline>
    </el-dialog>
  </div>
</template>
<script>
  import cityData from './cityData'

  export default {
    name: 'order',
    data() {
      return {
        // 搜索及分页信息
        queryInfo: {
          query: '',
          pagenum: 1,
          pagesize: 5,
        },
        // 总数据条数
        total: 0,
        // 订单列表
        orderList: [],
        // 控制修改对话框的显示与隐藏
        editAddressDialogVisible: false,
        // 编辑地址对象
        editAddressForm: {
          address1: [],
          address2: ''
        },
        // 编辑地址校验规则
        editAddressFormRules: {
          address1: [{
            required: true,
            message: '请选择省市区/县',
            trigger: 'blur'
          }],
          address2: [{
            required: true,
            message: '请输入详细地址',
            trigger: 'blur'
          }]
        },
        // 城市信息
        cityData,
        // 控制物流信息对话框的显示与隐藏
        progerssDialogVisible:false,
        // 物流信息
        progressInfo:[]
      }
    },
    components: {},
    created() {
      this.getOrderList()
    },
    methods: {
      // 获取订单列表
      async getOrderList() {
        await this.$http.get('orders', {
          params: this.queryInfo
        }).then(res => {
          if (res.data.meta.status === 200) {
            this.orderList = res.data.data.goods
            this.total = res.data.data.total
          } else {
            this.$message({
              type: 'error',
              message: res.data.meta.msg,
              duration: 2000
            })
          }
        })
      },
      //   每页条数发生变化
      handleSizeChange(newSize) {
        this.queryInfo.pagesize = newSize
        this.getOrderList()
      },
      //   页码发生变化
      handlePagechange(newPage) {
        this.queryInfo.pagenum = newPage
        this.getOrderList()
      },
      // 显示修改对话框
      showEditDialog() {
        this.editAddressDialogVisible = true
      },
      //   关闭修改对话框
      editAddressDialogClosed() {
        // this.$refs.editAddressFormRef.resetFields()
        this.editAddressForm.address1=[]
        this.editAddressForm.address2=''
        this.editAddressDialogVisible = false
      },
    //   显示物流信息
    async showProgressDialog(){
        await this.$http.get('/kuaidi/1106975712662').then(res => {
            if(res.data.meta.status === 200){
                this.progressInfo = res.data.data
                this.progerssDialogVisible = true
            }else{
                this.$message({
                    type:'error',
                    message:res.data.meta.msg,
                    duration:2000
                })
            }
        })
        
    },
    // 物流信息对话框关闭
    progerssDialogClosed(){
        this.progerssDialogVisible=false
    },
    }
  }

</script>
<style scoped>
  .el-cascader {
    width: 100%;
  }

</style>
